
$(function(){
		$("#schedule td").mousemove(function(){
			$(this).addClass("tdhover");
		});	
		$("#schedule td").mouseout(function(){
			$(this).removeClass("tdhover");
		});
		$("#schedule td").dblclick(function(){
			remove_div();
			var lesson_index=$(this).parent().index("tr")+'-'+$(this).index();//get lesson id
			var str = "<div class='creatediv'>";
				str+="<span>请输入课程名称:</span>";
				str+="<input id='lessonname' type='text' name='lessonname' value=''/>"; 
				str+="<span>自第<input type='text' id='startweek'/>周至第<input type='text' id='endweek'/>周</span>";
				str+="<input type='submit' value='保存' onclick='submit_data()'/>";
				str+="<input id='cancel' type='button' value='取消' onclick='remove_div()'/>";
				str+="</div>";
			$(this).append(str);
			$("div .creatediv").append("<input type='hidden' value='"+lesson_index+"'");
			$("#lessonname").focus();
		});
	})

function remove_div(){
	$(".creatediv :button").attr("disabled","disabled");
	$("div .creatediv").remove();
}

function loaddata(data,lesson_index){
	var trindex=lesson_index.split("-");
	//alert(trindex[0]+'-'+trindex[1]);
	$("#schedule tr").eq(trindex[0]).find("td").eq(trindex[1]-1).html(data);
}
function submit_data(){
	$(".creatediv :submit").attr("disabled","disabled");
	var lesson_index=$(".creatediv :hidden").val();
	var lesson_name=$("#lessonname").val();
	var startweek=$("#startweek").val();
	var endweek=$("#endweek").val();
	$.post(
			'service/service_schedule.php',
			{lesson_name:lesson_name,lesson_index:lesson_index,startweek:startweek,endweek:endweek},
			function(data){
				remove_div();
				$.get(
						'service/service_schedule.php',
						{lesson_index:lesson_index},
						function(date){
							loaddata(date,lesson_index);
						}
				);
			}
		);
	
}